{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ae7e4a0d",
   "metadata": {},
   "source": [
    "# THE CODE IS IN MY GITHUB!!!\n",
    "Go and checkout my github if you want the **to_candle** file!\n",
    "## https://github.com/kecoma1/Trading_BOT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b6630c9e",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import to_candle"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0c4acc1",
   "metadata": {},
   "source": [
    "### Metatrader dataframe\n",
    "The dataframe that metatrader metatrader provides with the csv file may not be the one we want. This is because MT5 gives us all the ticks of the price (which is wonderful)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "36b0373d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>&lt;DATE&gt;</th>\n",
       "      <th>&lt;TIME&gt;</th>\n",
       "      <th>&lt;BID&gt;</th>\n",
       "      <th>&lt;ASK&gt;</th>\n",
       "      <th>&lt;LAST&gt;</th>\n",
       "      <th>&lt;VOLUME&gt;</th>\n",
       "      <th>&lt;FLAGS&gt;</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2021.09.30</td>\n",
       "      <td>00:00:00.204</td>\n",
       "      <td>1.15982</td>\n",
       "      <td>1.15985</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2021.09.30</td>\n",
       "      <td>00:00:00.409</td>\n",
       "      <td>1.15939</td>\n",
       "      <td>1.16015</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2021.09.30</td>\n",
       "      <td>00:00:00.672</td>\n",
       "      <td>1.15984</td>\n",
       "      <td>1.15987</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2021.09.30</td>\n",
       "      <td>00:00:26.007</td>\n",
       "      <td>1.15978</td>\n",
       "      <td>1.15981</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2021.09.30</td>\n",
       "      <td>00:00:27.707</td>\n",
       "      <td>1.15984</td>\n",
       "      <td>1.15987</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2021.09.30</td>\n",
       "      <td>00:00:56.775</td>\n",
       "      <td>1.15983</td>\n",
       "      <td>1.15986</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2021.09.30</td>\n",
       "      <td>00:00:57.110</td>\n",
       "      <td>1.15982</td>\n",
       "      <td>1.15985</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2021.09.30</td>\n",
       "      <td>00:01:00.532</td>\n",
       "      <td>1.15982</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2021.09.30</td>\n",
       "      <td>00:01:01.369</td>\n",
       "      <td>1.15973</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2021.09.30</td>\n",
       "      <td>00:01:09.039</td>\n",
       "      <td>1.15978</td>\n",
       "      <td>1.15981</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       <DATE>        <TIME>    <BID>    <ASK>  <LAST>  <VOLUME>  <FLAGS>\n",
       "0  2021.09.30  00:00:00.204  1.15982  1.15985     NaN       NaN        6\n",
       "1  2021.09.30  00:00:00.409  1.15939  1.16015     NaN       NaN        6\n",
       "2  2021.09.30  00:00:00.672  1.15984  1.15987     NaN       NaN        6\n",
       "3  2021.09.30  00:00:26.007  1.15978  1.15981     NaN       NaN        6\n",
       "4  2021.09.30  00:00:27.707  1.15984  1.15987     NaN       NaN        6\n",
       "5  2021.09.30  00:00:56.775  1.15983  1.15986     NaN       NaN        6\n",
       "6  2021.09.30  00:00:57.110  1.15982  1.15985     NaN       NaN        6\n",
       "7  2021.09.30  00:01:00.532  1.15982      NaN     NaN       NaN        2\n",
       "8  2021.09.30  00:01:01.369  1.15973      NaN     NaN       NaN        2\n",
       "9  2021.09.30  00:01:09.039  1.15978  1.15981     NaN       NaN        6"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tick_df = pd.read_csv(\"EURUSD.csv\", sep=\"\\t\")\n",
    "tick_df.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "4e002080",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(110493, 7)"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tick_df.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "91db0af1",
   "metadata": {},
   "source": [
    "## Candle dataframe\n",
    "This dataframe is obtained through the from_tick_to_candle function. The dataframe contains the following columns:\n",
    "* **TIME-UTC**: UTC-TIME since epoch in seconds.\n",
    "* **OPEN**: Open price of that candle.\n",
    "* **CLOSE**: Close price of the candle.\n",
    "* **HIGH**: Highest price of the candle.\n",
    "* **LOW**: Lowest price of the candle."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "faf9c264",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TIME-UTC</th>\n",
       "      <th>OPEN</th>\n",
       "      <th>CLOSE</th>\n",
       "      <th>HIGH</th>\n",
       "      <th>LOW</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.632953e+09</td>\n",
       "      <td>1.15982</td>\n",
       "      <td>1.15968</td>\n",
       "      <td>1.16015</td>\n",
       "      <td>1.15939</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.632954e+09</td>\n",
       "      <td>1.15968</td>\n",
       "      <td>1.15983</td>\n",
       "      <td>1.15990</td>\n",
       "      <td>1.15964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.632955e+09</td>\n",
       "      <td>1.15983</td>\n",
       "      <td>1.15966</td>\n",
       "      <td>1.15983</td>\n",
       "      <td>1.15964</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.632956e+09</td>\n",
       "      <td>1.15966</td>\n",
       "      <td>1.15980</td>\n",
       "      <td>1.15997</td>\n",
       "      <td>1.15966</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.632956e+09</td>\n",
       "      <td>1.15980</td>\n",
       "      <td>1.15975</td>\n",
       "      <td>1.15990</td>\n",
       "      <td>1.15966</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1.632957e+09</td>\n",
       "      <td>1.15975</td>\n",
       "      <td>1.15985</td>\n",
       "      <td>1.15992</td>\n",
       "      <td>1.15970</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.632958e+09</td>\n",
       "      <td>1.15985</td>\n",
       "      <td>1.15981</td>\n",
       "      <td>1.15987</td>\n",
       "      <td>1.15979</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1.632959e+09</td>\n",
       "      <td>1.15981</td>\n",
       "      <td>1.15984</td>\n",
       "      <td>1.15986</td>\n",
       "      <td>1.15976</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>1.632960e+09</td>\n",
       "      <td>1.15984</td>\n",
       "      <td>1.15986</td>\n",
       "      <td>1.15991</td>\n",
       "      <td>1.15979</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1.632961e+09</td>\n",
       "      <td>1.15986</td>\n",
       "      <td>1.15999</td>\n",
       "      <td>1.16004</td>\n",
       "      <td>1.15984</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       TIME-UTC     OPEN    CLOSE     HIGH      LOW\n",
       "0  1.632953e+09  1.15982  1.15968  1.16015  1.15939\n",
       "1  1.632954e+09  1.15968  1.15983  1.15990  1.15964\n",
       "2  1.632955e+09  1.15983  1.15966  1.15983  1.15964\n",
       "3  1.632956e+09  1.15966  1.15980  1.15997  1.15966\n",
       "4  1.632956e+09  1.15980  1.15975  1.15990  1.15966\n",
       "5  1.632957e+09  1.15975  1.15985  1.15992  1.15970\n",
       "6  1.632958e+09  1.15985  1.15981  1.15987  1.15979\n",
       "7  1.632959e+09  1.15981  1.15984  1.15986  1.15976\n",
       "8  1.632960e+09  1.15984  1.15986  1.15991  1.15979\n",
       "9  1.632961e+09  1.15986  1.15999  1.16004  1.15984"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "candle_df = to_candle.from_tick_to_candle(\"EURUSD.csv\", 15*60)\n",
    "candle_df.head(10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "a1f458a6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(183, 5)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "candle_df.shape"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
